package cn.accp.videoPlayer;

import cn.accp.videoPlayer.base.Coder;
import cn.accp.videoPlayer.base.impl.AviCoder;
import cn.accp.videoPlayer.base.impl.MP4Coder;
import cn.accp.videoPlayer.base.impl.WmvCoder;

public class MediaPlayer {
	// 加码器接口
	private Coder coder;
	// 播放器内部信息
	private String message;

	private String fileName;

	// 加载文件,根据文件扩展名,实例化不同的解码器接口,并生成播放信息
	public void loadVideoFile(String fileName) {
		if (fileName == null || fileName == "") {
			this.message = "错误!没有文件，请先加载文件。";
		} else {
			this.message = "当前播放的文件为:" + fileName;
			String ex = FileNameHelper.getExtensionName(fileName);
			// switch(A),括号中A的取值可以是byte、short、int、char、String，还有枚举类型
			switch (ex) {
			case "avi":
				this.coder = new AviCoder();
				break;
			case "mp4":
				this.coder = new MP4Coder();
				break;
			case "wmv":
				this.coder = new WmvCoder();
				break;
			default:
				this.message = "错误！" + fileName + " 没有对应的解码器，请先下载加码器。";
				this.coder = null;
				break;
			}
		}
	}

	public void playVideo() {
		if (coder != null) {
			coder.play(this.fileName);
		}
		System.out.println(this.message);
	}

	public void pauseVideo() {
		if (coder != null) {
			coder.pause(this.fileName);
		}
		System.out.println(this.message);
	}

	public void fastVideo() {
		if (coder != null) {
			coder.fast(this.fileName);
		}
		System.out.println(this.message);

	}

	public void backVideo() {
		if (coder != null) {
			coder.back(this.fileName);
		}
		System.out.println(this.message);

	}

	public void stopVideo() {
		if (coder != null) {
			coder.stop(this.fileName);
		}
		System.out.println(this.message);
	}
}
